// @APIVersion 1.0.0
// @Title beego Test API
// @Description beego has a very cool tools to autogenerate documents for your API
// @Contact astaxie@gmail.com
// @TermsOfServiceUrl http://beego.me/
// @License Apache 2.0
// @LicenseUrl http://www.apache.org/licenses/LICENSE-2.0.html
package routers

import (
	"controllers"
	"controllers/configure"
	"controllers/server"
	"controllers/file"
	"controllers/script"
	"github.com/astaxie/beego"
	"github.com/astaxie/beego/plugins/cors"
	"time"
	"controllers/records"
)

func init() {
	beego.InsertFilter("*", beego.BeforeRouter, cors.Allow(&cors.Options{
		AllowAllOrigins:  true,
		AllowMethods:     []string{"GET", "POST", "PUT", "DELETE", "OPTIONS"},
		AllowHeaders:     []string{"Origin", "Authorization", "Access-Control-Allow-Origin", "Access-Control-Allow-Headers", "Content-Type"},
		ExposeHeaders:    []string{"Content-Length", "Access-Control-Allow-Origin", "Access-Control-Allow-Headers", "Content-Type"},
		MaxAge:           5 * time.Minute,
		AllowCredentials: true,
	}))

	beego.Router("/", &controllers.BaseRouter{})
	beego.Router("/login", &controllers.LoginController{})
	beego.Router("/logout", &controllers.LogoutController{})

	//server
	beego.Router("/server/server_list", &server.ServerOptController{},"get:ServerList")
	beego.Router("/server/account_list", &server.ServerOptController{},"get:AccountList")
	beego.Router("/server/add_account", &server.ServerOptController{},"get:AddAccount")
	beego.Router("/server/add_server", &server.ServerOptController{},"post:AddServer")
	beego.Router("/server/delete_server", &server.ServerOptController{},"delete:DeleteServer")

	//script
	beego.Router("/script/exec", &script.ScriptExecController{},"post:ExecTask")
	beego.Router("/script/list/:taskId", &script.ScriptListController{},"get:TaskDetail")
	beego.Router("/script/list", &script.ScriptListController{},"get:ScriptTaskList")
	//file
	beego.Router("/file/distribute", &file.FileDistributeController{},"post:FileDistribute")
	beego.Router("/file/upload", &file.FileDistributeController{},"post:UploadFile")
	beego.Router("/file/delete_upload", &file.FileDistributeController{},"delete:DeleteUploadFile")
	beego.Router("/file/list/:taskId", &file.FileTaskListController{},"get:TaskDetail")
	beego.Router("/file/list", &file.FileTaskListController{},"get:FileTaskList")

	//records
	beego.Router("/records/list",&records.RecordsOptController{},"get:RecordsList")

	beego.Router("/script/test", &script.ScriptExecController{},"get:ExecTest")

	ns := beego.NewNamespace("/v1",
		beego.NSNamespace("/console_script",
			beego.NSInclude(
				&controllers.ConsoleScriptController{},
			),
		),

		beego.NSNamespace("/system_role",
			beego.NSInclude(
				&controllers.SystemRoleController{},
			),
		),

		beego.NSNamespace("/system_user",
			beego.NSInclude(
				&controllers.SystemUserController{},
			),
		),

		beego.NSNamespace("/uw_graph",
			beego.NSInclude(
				&configure.UwGraphController{},
			),
		),

	)
	beego.AddNamespace(ns)
}
